import java.util.*;

class Student {
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
        // System.out.printf("hashCode = %d\n", this.hashCode());
    }

    public int hashCode() {
        return this.name.hashCode();
    }

    public boolean equals(Object obj) {
        Student s = (Student)obj;
        // System.out.printf("Student equals\n");
        // return (age == s.age);
        return name.equals(s.name);
    }

    public String toString() {
        return name + "@" + age;
    }
}

public class HashSetTest {
    static public void main(String [] args) {
        // HashSet<Student> o = new HashSet<Student>();
        Set<Student> o = new HashSet<Student>();

        o.add(new Student("张三", 35));
        o.add(new Student("张有", 36));
        o.add(new Student("张人", 37));
        o.add(new Student("张三", 38));

        Student s = new Student(new String("张三"), 38);
        if (o.contains(s)) {
            System.out.printf("存在!\n");
            o.remove(s);
        }

        Iterator<Student> it = o.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }
}
